/**
 *
 */
package com.sihai.ehr.web.action.ajax;

import com.sihai.core.beans.BeanInject;
import com.sihai.ehr.model.biz.DutyProxy;
import com.sihai.ehr.model.biz.WorkNo;
import com.sihai.ehr.model.sys.Organization;
import com.sihai.ehr.service.DutyProxyService;
import com.sihai.ehr.service.WorkNoService;
import com.sihai.ehr.web.action.EHRAction;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

/**
 * @author wxn
 * @since 2012-6-20 23:21
 */
public class DutyProxyAction extends EHRAction {

    private static final long serialVersionUID = 2121333028480225454L;

    @BeanInject
    private DutyProxyService dutyProxyService;
    
    private boolean result;

    private DutyProxy dutyProxy;

    //设置代理人
    @Action(value = "/ajax/proxy-set", results = {
            @Result(name = "success", type = "json", params = {"root", "result"})
    })
    public String set() {
        if(dutyProxy != null && dutyProxy.getId() != null){
            DutyProxy proxy = dutyProxyService.get(dutyProxy.getId());
            if(dutyProxy.getProxyOne() != null && dutyProxy.getProxyOne().getId() != null){
                proxy.setProxyOne(dutyProxy.getProxyOne());
            }
            if(dutyProxy.getProxyTwo() != null && dutyProxy.getProxyTwo().getId() != null){
                proxy.setProxyTwo(dutyProxy.getProxyTwo());
            }
            if(dutyProxy.getProxyThree() != null && dutyProxy.getProxyThree().getId() != null){
                proxy.setProxyThree(dutyProxy.getProxyThree());
            }
            dutyProxyService.save(proxy);

            result = true;
        }
        
        return SUCCESS;
    }

    public boolean isResult() {
        return result;
    }

    public void setResult(boolean result) {
        this.result = result;
    }

    public DutyProxy getDutyProxy() {
        return dutyProxy;
    }

    public void setDutyProxy(DutyProxy dutyProxy) {
        this.dutyProxy = dutyProxy;
    }
}
